package com.jdn;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * User: arsentyev
 * Date: 22.08.12
 */
public class FileUtils {
    public static void writeToFile(String fileName, String txt) {
        dirCheck(fileName.substring(0, fileName.lastIndexOf(File.separator)));
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(txt);
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            if(writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {/**/}
            }
        }
    }

    private static void dirCheck(String path) {
        new File(path).mkdirs();
    }
}